package com.ymatou.iapi.godmch.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godmch.parameter.createIndepMchBean;
import com.ymatou.iapi.godmch.parameter.editCSBean;
import com.ymatou.iapi.godmch.parameter.mchCreateCsBean;
import com.ymatou.iapi.godmch.service.createIndepMchCall;
import com.ymatou.iapi.godmch.service.editCSCall;
import com.ymatou.iapi.godmch.service.mchCreateCsCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.data.test;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.cs_info;
import com.ymttest.database.sqlwapper.godmch.DefGodMchWapper;
import com.ymttest.utils.TestDataManager;
/**
*编辑客服
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_editCS{
	private static editCSBean bean;
	private static editCSCall call;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("编辑客服");
	}

	@Before
	public void caseUp() {
		bean=new editCSBean();
		call=new editCSCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_editCS_001() {
		Logger.start(true,"正例-编辑客服-普通商户");
		try {
			
			mchCreateCsBean mchCreateCsBean=GodmchManageCallService.initMchCreateCsBean();
			GodmchManageCallService.mchCreateCsCall(mchCreateCsBean);
			
			cs_info csi=new DefGodMchWapper().selectCsInfoByMchId(mchCreateCsBean.getMchId()).get(0);
			bean.setMchId(mchCreateCsBean.getMchId());
			bean.setCsId(csi.getCsId());
			bean.setPassword("222aaaa");
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("200", call.getString("status"), "验证status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_editCS_001_1() {
		Logger.start(true,"正例-编辑客服-独立商户");
		try {
			
			createIndepMchBean createmchBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createmchBean);
			
			mchCreateCsBean mchCreateCsBean=GodmchManageCallService.initMchCreateCsBean();
			mchCreateCsBean.setMchId(createIndepMchCall.getmchId());
			mchCreateCsCall mchCreateCsCall=GodmchManageCallService.mchCreateCsCall(mchCreateCsBean);
			
			cs_info csi=new DefGodMchWapper().selectCsInfoByMchId(createIndepMchCall.getmchId()).get(0);
			bean.setMchId(createIndepMchCall.getmchId());
			bean.setCsId(csi.getCsId());
			bean.setPassword("222aaaa");
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("200", call.getString("status"), "验证status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_editCS_002() {
		Logger.start(true,"正例-编辑客服-mchId不存在");
		try {
			mchCreateCsBean mchCreateCsBean=GodmchManageCallService.initMchCreateCsBean();
			GodmchManageCallService.mchCreateCsCall(mchCreateCsBean);
			
			cs_info csi=new DefGodMchWapper().selectCsInfoByMchId(mchCreateCsBean.getMchId()).get(0);
			
			bean.setMchId(9999);
			bean.setCsId(csi.getCsId());
			bean.setPassword("222aaaa");
			call.setData(bean);
			call.callService();
			
			Logger.verifyEquals("5023", call.getString("status"), "验证status");
			Logger.verifyEquals(true, call.getString("msg").contains("客服信息不存在"), "验证status");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_editCS_003() {
		Logger.start(true,"正例-编辑客服-mchId为空");
		try {

			mchCreateCsBean mchCreateCsBean=GodmchManageCallService.initMchCreateCsBean();
			GodmchManageCallService.mchCreateCsCall(mchCreateCsBean);
			
			cs_info csi=new DefGodMchWapper().selectCsInfoByMchId(mchCreateCsBean.getMchId()).get(0);
			
			bean.setMchId(null);
			bean.setCsId(csi.getCsId());
			bean.setPassword("222aaaa");
			call.setData(bean);
			call.callService();
			
			Logger.verifyEquals("4001", call.getString("status"), "验证status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_editCS_004() {
		Logger.start(true,"正例-编辑客服-password为空,title、remark不为空");
		try {
			mchCreateCsBean mchCreateCsBean=GodmchManageCallService.initMchCreateCsBean();
			GodmchManageCallService.mchCreateCsCall(mchCreateCsBean);
			
			cs_info csi=new DefGodMchWapper().selectCsInfoByMchId(mchCreateCsBean.getMchId()).get(0);
			
			bean.setMchId(mchCreateCsBean.getMchId());
			bean.setCsId(csi.getCsId());
			bean.setPassword(null);
			bean.setTitle("title_"+TestDataManager.getRandomIntNum(5));
			bean.setRemark("remark_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();
			
			
			cs_info csi2=new DefGodMchWapper().selectCsInfoByMchId(bean.getMchId()).get(0);
			Logger.verifyEquals("200", call.getString("status"), "验证status");

			Logger.verifyEquals(bean.getMchId(), csi2.getMchId(), "验证mchId");
			Logger.verifyEquals(mchCreateCsBean.getTemplateId(), csi.getTempldateId(), "验证TemplateId");
			Logger.verifyEquals(bean.getTitle(), csi2.getTitle(), "验证Title");
			Logger.verifyEquals(bean.getRemark(), csi2.getRemark(), "验证Remark");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_editCS_004_1() {
		Logger.start(true,"正例-编辑客服-password格式验证");
		try {
			mchCreateCsBean mchCreateCsBean=GodmchManageCallService.initMchCreateCsBean();
			GodmchManageCallService.mchCreateCsCall(mchCreateCsBean);
			
			cs_info csi=new DefGodMchWapper().selectCsInfoByMchId(mchCreateCsBean.getMchId()).get(0);
			
			bean.setMchId(mchCreateCsBean.getMchId());
			bean.setCsId(csi.getCsId());
			bean.setPassword("222");
			call.setData(bean);
			call.callService();
			
			Logger.verifyEquals("5000", call.getString("status"), "验证status");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_editCS_005() {
		Logger.start(true,"正例-编辑客服-title为空,password、remark不为空");
		try {

			mchCreateCsBean mchCreateCsBean=GodmchManageCallService.initMchCreateCsBean();
			GodmchManageCallService.mchCreateCsCall(mchCreateCsBean);
			
			cs_info csi=new DefGodMchWapper().selectCsInfoByMchId(mchCreateCsBean.getMchId()).get(0);
			
			bean.setMchId(mchCreateCsBean.getMchId());
			bean.setCsId(csi.getCsId());
			bean.setPassword("222aaa");
		//	bean.setTitle("title_"+TestDataManager.getRandomIntNum(5));
			bean.setRemark("remark_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();
					
			cs_info csi2=new DefGodMchWapper().selectCsInfoByMchId(bean.getMchId()).get(0);
			Logger.verifyEquals("200", call.getString("status"), "验证status");

			Logger.verifyEquals(bean.getMchId(), csi2.getMchId(), "验证mchId");
			Logger.verifyEquals(mchCreateCsBean.getTemplateId(), csi.getTempldateId(), "验证TemplateId");
			//Logger.verifyEquals(bean.getTitle(), csi2.getTitle(), "验证Title");
			Logger.verifyEquals(bean.getRemark(), csi2.getRemark(), "验证Remark");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_editCS_006() {
		Logger.start(true,"正例-编辑客服-remark为空,password、title不为空");
		try {

			mchCreateCsBean mchCreateCsBean=GodmchManageCallService.initMchCreateCsBean();
			GodmchManageCallService.mchCreateCsCall(mchCreateCsBean);
			
			cs_info csi=new DefGodMchWapper().selectCsInfoByMchId(mchCreateCsBean.getMchId()).get(0);
			
			bean.setMchId(mchCreateCsBean.getMchId());
			bean.setCsId(csi.getCsId());
			bean.setPassword("222aaa");
			bean.setTitle("title_"+TestDataManager.getRandomIntNum(5));
			//bean.setRemark("remark_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();
					
			cs_info csi2=new DefGodMchWapper().selectCsInfoByMchId(bean.getMchId()).get(0);
			Logger.verifyEquals("200", call.getString("status"), "验证status");

			Logger.verifyEquals(bean.getMchId(), csi2.getMchId(), "验证mchId");
			Logger.verifyEquals(mchCreateCsBean.getTemplateId(), csi.getTempldateId(), "验证TemplateId");
			Logger.verifyEquals(bean.getTitle(), csi2.getTitle(), "验证Title");
			//Logger.verifyEquals(bean.getRemark(), csi2.getRemark(), "验证Remark");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_editCS_007() {
		Logger.start(true,"正例-编辑客服-password、title为空");
		try {
			mchCreateCsBean mchCreateCsBean=GodmchManageCallService.initMchCreateCsBean();
			GodmchManageCallService.mchCreateCsCall(mchCreateCsBean);
			
			cs_info csi=new DefGodMchWapper().selectCsInfoByMchId(mchCreateCsBean.getMchId()).get(0);
			
			bean.setMchId(mchCreateCsBean.getMchId());
			bean.setCsId(csi.getCsId());
			//bean.setPassword("222aaa");
			//bean.setTitle("title_"+TestDataManager.getRandomIntNum(5));
			bean.setRemark("remark_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();
					
			cs_info csi2=new DefGodMchWapper().selectCsInfoByMchId(bean.getMchId()).get(0);
			Logger.verifyEquals("200", call.getString("status"), "验证status");

			Logger.verifyEquals(bean.getMchId(), csi2.getMchId(), "验证mchId");
			Logger.verifyEquals(mchCreateCsBean.getTemplateId(), csi.getTempldateId(), "验证TemplateId");
			Logger.verifyEquals(mchCreateCsBean.getTitle(), csi2.getTitle(), "验证Title");
			Logger.verifyEquals(bean.getRemark(), csi2.getRemark(), "验证Remark");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_editCS_008() {
		Logger.start(true,"正例-编辑客服-password、remark为空");
		try {
			mchCreateCsBean mchCreateCsBean=GodmchManageCallService.initMchCreateCsBean();
			GodmchManageCallService.mchCreateCsCall(mchCreateCsBean);
			
			cs_info csi=new DefGodMchWapper().selectCsInfoByMchId(mchCreateCsBean.getMchId()).get(0);
			
			bean.setMchId(mchCreateCsBean.getMchId());
			bean.setCsId(csi.getCsId());
			//bean.setPassword("222aaa");
			bean.setTitle("title_"+TestDataManager.getRandomIntNum(5));
			//bean.setRemark("remark_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();
					
			cs_info csi2=new DefGodMchWapper().selectCsInfoByMchId(bean.getMchId()).get(0);
			Logger.verifyEquals("200", call.getString("status"), "验证status");

			Logger.verifyEquals(bean.getMchId(), csi2.getMchId(), "验证mchId");
			Logger.verifyEquals(mchCreateCsBean.getTemplateId(), csi2.getTempldateId(), "验证TemplateId");
			Logger.verifyEquals(bean.getTitle(), csi2.getTitle(), "验证Title");
			//Logger.verifyEquals(bean.getRemark(), csi2.getRemark(), "验证Remark");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_editCS_009() {
		Logger.start(true,"正例-编辑客服-title、remark为空");
		try {
			mchCreateCsBean mchCreateCsBean=GodmchManageCallService.initMchCreateCsBean();
			GodmchManageCallService.mchCreateCsCall(mchCreateCsBean);
			
			cs_info csi=new DefGodMchWapper().selectCsInfoByMchId(mchCreateCsBean.getMchId()).get(0);
			
			bean.setMchId(mchCreateCsBean.getMchId());
			bean.setCsId(csi.getCsId());
			bean.setPassword("222aaa");
			//bean.setTitle("title_"+TestDataManager.getRandomIntNum(5));
			//bean.setRemark("remark_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();
					
			cs_info csi2=new DefGodMchWapper().selectCsInfoByMchId(bean.getMchId()).get(0);
			Logger.verifyEquals("200", call.getString("status"), "验证status");

			Logger.verifyEquals(bean.getMchId(), csi2.getMchId(), "验证mchId");
			Logger.verifyEquals(mchCreateCsBean.getTemplateId(), csi2.getTempldateId(), "验证TemplateId");
			Logger.verifyEquals(mchCreateCsBean.getTitle(), csi2.getTitle(), "验证Title");
			//Logger.verifyEquals(bean.getRemark(), csi2.getRemark(), "验证Remark");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_editCS_009_1() {
		Logger.start(true,"正例-编辑客服-loginId不为空，title、remark为空");
		try {
			mchCreateCsBean mchCreateCsBean=GodmchManageCallService.initMchCreateCsBean();
			GodmchManageCallService.mchCreateCsCall(mchCreateCsBean);
			
			cs_info csi=new DefGodMchWapper().selectCsInfoByMchId(mchCreateCsBean.getMchId()).get(0);
			
			bean.setMchId(mchCreateCsBean.getMchId());
			bean.setCsId(csi.getCsId());
			bean.setPassword("222aaa");
			bean.setLoginId("测试loginId_"+TestDataManager.getRandomIntNum(5));
			//bean.setTitle("title_"+TestDataManager.getRandomIntNum(5));
			//bean.setRemark("remark_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();
					
			cs_info csi2=new DefGodMchWapper().selectCsInfoByMchId(bean.getMchId()).get(0);
			Logger.verifyEquals("200", call.getString("status"), "验证status");

			Logger.verifyEquals(bean.getMchId(), csi2.getMchId(), "验证mchId");
			Logger.verifyEquals(mchCreateCsBean.getTemplateId(), csi2.getTempldateId(), "验证TemplateId");
			Logger.verifyEquals(mchCreateCsBean.getTitle(), csi2.getTitle(), "验证Title");
			//Logger.verifyEquals(bean.getLoginId(), csi2.get(), "验证Remark");	
			//Logger.verifyEquals(bean.getRemark(), csi2.getRemark(), "验证Remark");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_editCS_010() {
		Logger.start(true,"正例-编辑客服-Loginid,password、title、remark都为空");
		try {
			
			mchCreateCsBean mchCreateCsBean=GodmchManageCallService.initMchCreateCsBean();
			GodmchManageCallService.mchCreateCsCall(mchCreateCsBean);
			
			cs_info csi=new DefGodMchWapper().selectCsInfoByMchId(mchCreateCsBean.getMchId()).get(0);
			
			bean.setMchId(mchCreateCsBean.getMchId());
			bean.setCsId(csi.getCsId());
			//bean.setPassword("222aaa");
			//bean.setTitle("title_"+TestDataManager.getRandomIntNum(5));
			//bean.setRemark("remark_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();
					
			Logger.verifyEquals("4001", call.getString("status"), "验证status");

			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}